package com.flu.holidays.consumer.controller;


import cn.hutool.json.JSONArray;
import cn.hutool.json.JSONObject;
import com.flu.holidays.consumer.result.AjaxResult;
import com.flu.holidays.modeel.DayTypeModel;
import com.flu.holidays.service.HolidayService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Controller;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.Valid;
import javax.validation.constraints.Pattern;

@Slf4j
@Validated
@Controller("/day")
@RestController
@Tag(name = "1000.法定节假日服务")
public class HolidayController {




    @Resource
    private HolidayService holidayService;
    @Operation(summary = "日期")
    @GetMapping({"/day/type"})
    public AjaxResult<DayTypeModel> getDayType(@Parameter(description = "日期") @RequestParam
                                  @Valid @Pattern(regexp = "^\\d{4}-\\d{2}-\\d{2}$", message = "日期格式错误") String  date) {
        log.info("调用日期服务，日期:{}",date);
        return AjaxResult.successData(holidayService.getDayType(date));
    }

    @Operation(summary = "获取json格式配置")
    @GetMapping({"/config"})
    public AjaxResult<JSONObject> getJsonConfig() {
        return AjaxResult.successData(holidayService.getJsonConfig());
    }

}
